package com.mx.project.services.impl;

import com.mx.project.dao.CartMapper;
import com.mx.project.pojo.Cart;
import com.mx.project.vo.CartInfo;
import com.mx.project.services.CartService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CartServiceImpl implements CartService {
    @Autowired
    private CartMapper cartMapper;

    @Override
    public int addCart(Cart cart) {
        return cartMapper.insertSelective(cart);
    }

    @Override
    public List<CartInfo> getCartByUid(Integer uid) {
        return cartMapper.selectCartInfoByUid(uid);
    }

    @Override
    public Cart getCartBySidAndUid(Integer pid, Integer uid) {
        return cartMapper.selectCartByCidAndUid(pid,uid);
    }

    @Override
    public int cartCountAdd(Integer uid,Integer sid, Integer count) {
        return cartMapper.updateCartCount(sid,count);
    }

    @Override
    public int removeCartByPidAndUid(Integer pid, Integer uid) {
        return cartMapper.deleteByPidAndUid(pid,uid);
    }

    @Override
    public int updateMulCartCount(Integer uid, List<CartInfo> lists) {
        int count = 0;
        for (CartInfo list : lists) {
            count += cartMapper.updateMulCartCount(uid,list.getCount(),list.getPid());
        }
        return count;
    }

    @Override
    public int removeCartByUid(Integer uid) {
        return cartMapper.deleteByUid(uid);
    }
}
